﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CO2FixCalibration
{
    class ReadMeasurements
    {
        static DataSet[] measurementspersite;

        public static DataSet[] MeasurementsPerSite
        {
            get
            { 
                return measurementspersite;
            }
        }

        public static string[] Labels
        { 
            get
            {
                List<string> l = new List<string>();
                foreach (DataSet d in MeasurementsPerSite)
                {
                    l.Add(d.Label);
                }
                return l.ToArray();
            }
        }

        public static void Read(string filename, out double MaxInitMeas)
        {
            string[] content = System.IO.File.ReadAllLines(filename);
            MaxInitMeas = double.MinValue;
                
            List<DataSet> data = new List<DataSet>(content[0].Split('\t').Length -1);

            for (int col = 1; col < content[0].Split('\t').Length; col++)
            {
                data.Add(new DataSet(content[0].Split('\t')[col]));
            }

            for(int r=1;r<content.Length;r++)
            {
                for (int col = 1; col < content[0].Split('\t').Length; col++)
                {
                   
                    int year = int.Parse(content[r].Split('\t')[0]);
                    double value = double.Parse(content[r].Split('\t')[col]);
                    data[col - 1].Add(year, value);
                    if (r == 1 && value > MaxInitMeas) MaxInitMeas = value;
                }
            }
            measurementspersite = data.ToArray();
        }
    }
}
